using System.Web.UI;

namespace BilSimser.SharePoint.Common.Controls
{
	public class OWSTextField : OWSBase
	{
		#region construction

		/// <summary>
		/// Default constructor
		/// </summary>
		public OWSTextField()
		{
		}

		#endregion

		#region custom properties

		/// <summary>
		/// Gets or set the number of lines for the richtext control. 
		/// </summary>
		public int NumLines
		{
			get
			{
				if (ViewState["NumLines"] == null)
					NumLines = 1;
				return (int) ViewState["NumLines"];
			}
			set { ViewState["NumLines"] = value; }
		}

		#endregion

		#region overridden methods

		/// <summary>
		/// Renders the OWS Control
		/// </summary>
		/// <param name="wtr">writes out the text control information</param>
		protected override void Render (HtmlTextWriter wtr)
		{
			wtr.Write(
				"<SCRIPT>" +
					"fld = new {4}(frm, \"{0}\", \"{1}\", \"{2}\"); " +
					"fld.fRequired = {3}; " +
					"{5}" +
					"fld.IMEMode=\"\"; " +
					"fld.BuildUI(); " +
					"</SCRIPT>",
				UniqueID,
				Display,
				JavaScriptValue,
				Required.ToString().ToLower(),
				(NumLines == 1) ? "TextField" : "NoteField",
				(NumLines == 1) ?
					"fld.cchMaxLength = \"\"; " +
						"fld.cchDisplaySize = \"\"; " :
					string.Format("fld.stNumLines = \"{0}\"; ", NumLines)
				);
		}

		#endregion
	}
}